home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Games / WHDLoad / Autodoc / whdload.doc
Encoding:
Text File  |  2001-09-23  |  83.3 KB  |  2,198 lines

  1. TABLE OF CONTENTS
  2.  
  3. WHDLoad/--Overview--
  4. WHDLoad/resload_Abort
  5. WHDLoad/resload_Control
  6. WHDLoad/WHDLTAG_CBAF_SET
  7. WHDLoad/WHDLTAG_CBSWITCH_SET
  8. WHDLoad/WHDLTAG_IOERR_GET
  9. WHDLoad/resload_CRC16
  10. WHDLoad/resload_Decrunch
  11. WHDLoad/resload_Delay
  12. WHDLoad/resload_Delta
  13. WHDLoad/resload_DeleteFile
  14. WHDLoad/resload_DiskLoad
  15. WHDLoad/resload_DiskLoadDev
  16. WHDLoad/resload_FlushCache
  17. WHDLoad/resload_GetFileSize
  18. WHDLoad/resload_GetFileSizeDec
  19. WHDLoad/resload_ListFiles
  20. WHDLoad/resload_LoadFile
  21. WHDLoad/resload_LoadFileDecrunch
  22. WHDLoad/resload_LoadFileOffset
  23. WHDLoad/resload_LoadKick
  24. WHDLoad/resload_Patch
  25. WHDLoad/resload_ProtectRead
  26. WHDLoad/resload_ProtectReadWrite
  27. WHDLoad/resload_ProtectRemove
  28. WHDLoad/resload_ProtectSMC
  29. WHDLoad/resload_ProtectWrite
  30. WHDLoad/resload_Relocate
  31. WHDLoad/resload_SaveFile
  32. WHDLoad/resload_SaveFileOffset
  33. WHDLoad/resload_SetCACR
  34. WHDLoad/resload_SetCPU
  35. WHDLoad.Slave/--Overview--
  36.  
  37. WHDLoad/--Overview--
  38.  
  39. The calling conventions for all functions are similar to the OS-Library-
  40. concept. Parameters are provided in registers (except "resload_Abort"),
  41. return codes comes in D0 (on some functions also in D1). After a function call
  42. the registers D0-D1/A0-A1 are destroyed (D0,D1 may contain a returncode) they
  43. are so called scratch registers. All other registers are preserved.
  44. The base of the JMP tower in WHDLoad is similar to a LibraryBase. In
  45. difference to the OS the base must not stand in A6 on calling a function, but
  46. it is recommend to call all functions relative to a address register like
  47.         move.l  (_resload,pc),a5
  48.         jsr     (resload_Decrunch,a5)
  49. The resload base is overgiven in A0 on calling the Slave first via
  50. ws_GameLoader (see chapter WHDLoad.Slave/--Overview--).
  51.  
  52.  
  53. some keywords used in this document:
  54.  
  55.  Slave          the file which contains the interface code
  56.                 (see section WHDLoad.Slave/--Overview--)
  57.  
  58.  BaseMem        the memory which is used by the installed program, because
  59.                 this memory is always Chip-memory and starts at address
  60.                 $00000000, BaseMem is at the same time the size and the end
  61.                 address of the used Chip-memory BaseMem is specified in the
  62.                 Slave-structure in field "ws_BaseMemSize"
  63.  
  64.  ExpMem         is the expansions memory, a extra memory area which can
  65.                 optionally requested by the Slave-structure, it may be
  66.                 Chip- or Fast-memory dependedly on what is available
  67.                 ExpMem is supported starting WHDLoad version 8
  68.  
  69.  DiskImage      a floppy disk stored as a file on hard disk
  70.  
  71. logical values used for returncodes (see dos/dos.i):
  72.  TRUE = -1 (or better <>0)
  73.  FALSE = 0
  74.  
  75. WHDLoad/resload_Abort
  76.  
  77.    NAME
  78.         resload_Abort -- quit and return to operating system
  79.  
  80.    SYNOPSIS
  81.         resload_Abort( success, primary, secondary)
  82.                          (a7)    (4,a7)    (8,a7)
  83.                         ULONG    ULONG     ULONG
  84.  
  85.    FUNCTION
  86.         aborts and terminates the installed program and cause WHDLoad to
  87.         return to the operating system
  88.  
  89.    INPUTS
  90.         success -   the reason for aborting
  91.                     one of TDREASON_#? defined in the include file "whdload.i"
  92.                     depending on this value WHDLoad continues different
  93.                 TDREASON_OK
  94.                     a normal exit will performed
  95.                 TDREASON_DEBUG
  96.                     WHDLoad will create dump files (.whdl_dump, .whdl_memory,
  97.                     .whdl_register) and exit
  98.                 TDREASON_#? (except the above)
  99.                     WHDLoad will show an requester which displays the reason
  100.                     of aborting and requests the user to choose between
  101.                     "Quit", "Restart" and "Make CoreDump"
  102.         primary -   the primary return code further describing the reason of
  103.                     aborting
  104.                 TDREASON_DELETEFILE, TDREASON_DISKLOAD, TDREASON_DISKLOADDEV,
  105.                 TDREASON_DOSLIST, TDREASON_DOSREAD, TDREASON_DOSWRITE
  106.                     dos or trackdisk errorcode
  107.                 TDREASON_DEBUG
  108.                     program counter (so it can by written to the dump files)
  109.                 TDREASON_OSEMUFAIL
  110.                     name of the filed subsystem
  111.                 TDREASON_FAILMSG
  112.                     message to display
  113.                 TDREASON_MUSTNTSC, TDREASON_MUSTPAL, TDREASON_MUSTREG,
  114.                 TDREASON_OK, TDREASON_REQ68020, TDREASON_REQAGA,
  115.                 TDREASON_WRONGVER
  116.                     unused (can be omitted)
  117.         secondary - the secondary return code further describing the reason of
  118.                     aborting
  119.                 TDREASON_DELETEFILE, TDREASON_DOSREAD, TDREASON_DOSWRITE
  120.                     filename
  121.                 TDREASON_DISKLOAD
  122.                     disk number
  123.                 TDREASON_DOSLIST
  124.                     name of directory scanned
  125.                 TDREASON_DEBUG
  126.                     status register (so it can by written to the dump files)
  127.                 TDREASON_OSEMUFAIL
  128.                     error number, depending on the primary return code
  129.                 TDREASON_DISKLOADDEV, TDREASON_FAILMSG, TDREASON_MUSTNTSC,
  130.                 TDREASON_MUSTPAL, TDREASON_MUSTREG, TDREASON_OK,
  131.                 TDREASON_REQ68020, TDREASON_REQAGA, TDREASON_WRONGVER
  132.                     unused (can be omitted)
  133.  
  134.    EXAMPLE
  135.         to simply quit:
  136.                 ;primary and secondary wont be needed
  137.                 move.l  #TDREASON_OK,-(a7)
  138.                 move.l  (_resload,pc),a0
  139.                 jmp     (resload_Abort,a0)
  140.         to quit because reading of a file has failed:
  141.                 move.l  a0,-(a7)                        ;a0 = filename
  142.                 move.l  d0,-(a7)                        ;d0 = doserror code
  143.                 move.l  #TDREASON_DOSREAD,-(a7)
  144.                 move.l  (_resload,pc),-(a7)
  145.                 add.l   #resload_Abort,(a7)
  146.                 rts
  147.  
  148.    RESULT
  149.         nothing because WHDLoad will never return from this call
  150.  
  151.    BUGS
  152.  
  153.    NOTE
  154.         this routine is the only one which must be called via JMP and not JSR
  155.         because the parameters are located on the stack (this has the
  156.         advantage that if aborting because TDREASON_DEBUG all registers can be
  157.         preserved and written to the dump files by WHDLoad for further
  158.         diagnostics)
  159.  
  160.    SEE ALSO
  161.         example Slave sources provided with the WHDLoad developer package
  162.  
  163. WHDLoad/resload_Control
  164.  
  165.    NAME
  166.         resload_Control
  167.  
  168.    SYNOPSIS
  169.         success = resload_Control(tags)
  170.           D0                       A0
  171.          BOOL                    STRUCT
  172.  
  173.    FUNCTION
  174.         control function of WHDLoad, allows to get and set various variables
  175.         concerning the software and hardware configuration and to control the
  176.         behavior of some WHDLoad operations
  177.  
  178.    INPUTS
  179.         tags - pointer to a table of tagitems
  180.  
  181.         the following items are currently supported:
  182.  
  183.         WHDLTAG_ATTNFLAGS_GET   - gets the AttnFlags describing the current
  184.                                   CPU, FPU and MMU, the returned value is
  185.                                   similar to execbase.AttnFlags but not equal
  186.                                   because WHDLoad uses some additional bits,
  187.                                   the Slave is only allowed to the use the
  188.                                   defines from the standard include file
  189.                                   "exec/execbase.i" for testing the returned
  190.                                   value
  191.         WHDLTAG_BUILD_GET       - gets WHDLoad build number
  192.         WHDLTAG_BUTTONWAIT_GET  - returns -1 if WHDLoad option ButtonWait/S
  193.                                   has been enabled, otherwise returns 0
  194.         WHDLTAG_CBAF_SET        - sets a function which will be executed when
  195.                                   an access fault exception occurs (see
  196.                                   section WHDLoad/WHDLTAG_CBAF_SET for further
  197.                                   informations)
  198.         WHDLTAG_CBSWITCH_SET    - sets a function which will be executed when
  199.                                   WHDLoad switches from the operating system
  200.                                   to the installed program (see section
  201.                                   WHDLoad/WHDLTAG_CBSWITCH_SET for further
  202.                                   informations)
  203.         WHDLTAG_CHKBLTHOG       - enables the 'dmacon.blthog' check, requires
  204.                                   a active Snoop option and WHDLoad v13
  205.         WHDLTAG_CHKBLTSIZE      - enables the 'blitter size' check, requires a
  206.                                   active Snoop option and WHDLoad v13
  207.         WHDLTAG_CHKBLTWAIT      - enables the 'blitter wait' check, requires a
  208.                                   active Snoop option and WHDLoad v13
  209.         WHDLTAG_CHKCOLBST       - enables the 'bplcon0.color' check, requires
  210.                                   a active Snoop option and WHDLoad v13
  211.         WHDLTAG_CHIPREVBITS_GET - gets the ChipRevBits describing the current
  212.                                   custom chips, see standard include file
  213.                                   "graphics/gfxbase.i" for further explanation
  214.         WHDLTAG_CUSTOM1_GET
  215.         WHDLTAG_CUSTOM2_GET
  216.         WHDLTAG_CUSTOM3_GET
  217.         WHDLTAG_CUSTOM4_GET
  218.         WHDLTAG_CUSTOM5_GET     - returns numerical value of WHDLoad option
  219.                                   Custom1/N .. Custom5/N
  220.         WHDLTAG_ECLOCKFREQ_GET  - gets the EClockFrequency, which is the
  221.                                   frequency the custom chips operate on, the
  222.                                   value is taken from the execbase (see
  223.                                   standard include file "exec/execbase.i")
  224.         WHDLTAG_LANG_GET        - get language provided by lowlevel.library,
  225.                                   see libraries/lowlevel.i for further infos,
  226.                                   requires WHDLoad v13.2
  227.         WHDLTAG_IOERR_GET       - gets the dos errorcode of the previously
  228.                                   executed resload function
  229.         WHDLTAG_KEYTRANS_GET    - get pointer to a table for 'rawkey to ascii'
  230.                                   conversion, the table has a length of 512
  231.                                   bytes and contains 4 sub tables, first 128
  232.                                   bytes representing the keys pressed without
  233.                                   any modifier, then 128 bytes with Shift,
  234.                                   then 128 bytes with Alt and last 128 Bytes
  235.                                   with Shift and Alt
  236.                                   the tables are created from the actual
  237.                                   system keymap, dead keys are mapped like
  238.                                   pressing Space afterwards, keys resulting in
  239.                                   multibyte characters (F-Keys, Esc, ...) are
  240.                                   set to 0 in the tables
  241.         WHDLTAG_MONITOR_GET     - gets the used monitor/video mode, the
  242.                                   returned value is one of NTSC_MONITOR_ID and
  243.                                   PAL_MONITOR_ID (defined in the standard
  244.                                   include file "graphics/modeid.i"), the
  245.                                   WHDLoad options PAL/S and NTSC/S are
  246.                                   affecting the monitor/video mode
  247.         WHDLTAG_REVISION_GET    - gets WHDLoad minor version number
  248.         WHDLTAG_TIME_GET        - gets current time and date, returned will be
  249.                                   a pointer to a filled whdload_time structure
  250.                                   which is decribed in the include file
  251.                                   "whdload.i"
  252.         WHDLTAG_VERSION_GET     - gets WHDLoad major version number
  253.  
  254.    EXAMPLE
  255.         check if current CPU is at least an MC68020:
  256.                 ...
  257.                 clr.l   -(a7)                           ;TAG_DONE
  258.                 clr.l   -(a7)                           ;data to fill
  259.                 move.l  #WHDLTAG_ATTNFLAGS_GET,-(a7)
  260.                 move.l  a7,a0
  261.                 move.l  (_resload,pc),a2
  262.                 jsr     (resload_Control,a2)
  263.                 move.w  (6,a7),d0                       ;D0 = AttnFlags
  264.                 lea     (12,a7),a7                      ;restore sp
  265.                 btst    #AFB_68020,d0
  266.                 beq     .no68020
  267.                 ...
  268.         get video mode and CPU:
  269.                 ...
  270.                 lea     (_tags,pc),a0
  271.                 move.l  (_resload,pc),a2
  272.                 jsr     (resload_Control,a2)
  273.                 move.l  (_mon,pc),d0                    ;D0 = video mode
  274.                 cmp.l   #NTSC_MONITOR_ID,d0
  275.                 beq     .ntsc
  276.                 ...
  277.  
  278.         _tags   dc.l    WHDLTAG_MONITOR_GET
  279.         _mon    dc.l    0
  280.                 dc.l    WHDLTAG_ATTNFLAGS_GET
  281.                 dc.w    0                               ;padding
  282.         _attn   dc.w    0
  283.                 dc.l    0                               ;TAG_DONE
  284.  
  285.    RESULT
  286.         success is true if all items in the taglist has been successfully
  287.         processed
  288.  
  289.    BUGS
  290.  
  291.    NOTE
  292.         requires ws_Version >= 5
  293.  
  294.    SEE ALSO
  295.  
  296. WHDLoad/WHDLTAG_CBAF_SET
  297.  
  298.    NAME
  299.         WHDLTAG_CBAF_SET
  300.  
  301.    SYNOPSIS
  302.         to be used with resload_Control
  303.  
  304.         cont, adr,  data = CBAF(mode, size,  pc,  adr,  data)
  305.          D0    A1    A2          D0    D1    A0    A1    A2
  306.         LONG  APTR  APTR        LONG  LONG  APTR  APTR  APTR
  307.  
  308.    FUNCTION
  309.         using this tag a function can be set which will executed when an
  310.         access fault exception occurs which is not handled by WHDLoad itself,
  311.         it may be used to locate specific accesses in conjunction with
  312.         resload_Protect and to walk around invalid accesses during the
  313.         development process
  314.         using this tag all access faults can be catched except:
  315.          - instruction stream faults
  316.          - faults caused by WHDLoad's blitwait and blitsize checks
  317.         the routine set using this tag must not change any registers except
  318.         the ones holding a return value, the routine must return via RTS, on
  319.         entering the routine all interrupts are disabled (sr=$27xx)
  320.  
  321.    INPUTS
  322.         mode - transfer mode of the faulted access
  323.                 0 - read
  324.                 1 - modify (only 68040/060)
  325.                 2 - write
  326.         size - operand size of the attempted access
  327.                 1 - Byte
  328.                 2 - Word
  329.                 4 - LongWord
  330.         pc   - program counter of the instruction which has faulted
  331.                (warning this may sometimes already the instruction after the
  332.                one which has faulted, read the appropriate microprocessor user
  333.                manual for further informations)
  334.         adr  - the address which has been attempted to access
  335.         data - valid only on write operations, the given memory address
  336.                contains the data which has been tried to write
  337.  
  338.    RESULT
  339.         cont - how to continue
  340.                 0 - terminate, WHDLoad will show a requester notifying the
  341.                     access fault
  342.                 1 - proceed, the faulted access will be emulated by the
  343.                     handler inside great WHDLoad
  344.         adr  - in case of cont=proceed the address which will be accessed
  345.         data - in case of cont=proceed and mode=write a pointer to the data
  346.                which will be written (only 68030)
  347.  
  348.    EXAMPLE
  349.         if you want to get informed at which point the installed program
  350.         writes the value 42 to the address $BABE, use the following code:
  351.                 ...
  352.                 clr.l   -(a7)                           ;TAG_DONE
  353.                 pea     (_af,pc)                        ;function
  354.                 move.l  #WHDLTAG_CBAF_SET,-(a7)
  355.                 move.l  a7,a0
  356.                 move.l  (_resload,pc),a2
  357.                 jsr     (resload_Control,a2)
  358.                 lea     (12,a7),a7                      ;restore sp
  359.                 moveq   #2,d0
  360.                 lea     ($BABE),a0
  361.                 jsr     (resload_ProtectWrite,a2)       ;protect area
  362.                 ...
  363.  
  364.      _af        cmp.l   #$BABE,a1                       ;correct address ?
  365.                 bne     .term
  366.                 cmp.w   #2,d1                           ;size
  367.                 bne     .term
  368.                 cmp.w   #42,(a2)
  369.                 beq     .term
  370.                 moveq   #1,d0                           ;proceed
  371.                 rts
  372.  
  373.     .term       moveq   #0,d0                           ;terminate
  374.                 rts
  375.  
  376.    EXAMPLE
  377.         if want you to redirect an access to $24 to the address $300, use the
  378.         following code:
  379.                 ...
  380.                 clr.l   -(a7)                           ;TAG_DONE
  381.                 pea     (_af,pc)                        ;function
  382.                 move.l  #WHDLTAG_CBAF_SET,-(a7)
  383.                 move.l  a7,a0
  384.                 move.l  (_resload,pc),a2
  385.                 jsr     (resload_Control,a2)
  386.                 lea     (12,a7),a7                      ;restore sp
  387.                 moveq   #4,d0
  388.                 lea     ($24),a0
  389.                 jsr     (resload_ProtectWrite,a2)       ;protect area
  390.                 ...
  391.  
  392.      _af        cmp.l   #$24,a1                         ;correct address ?
  393.                 bne     .term
  394.                 lea     ($300),a1
  395.                 moveq   #1,d0                           ;proceed
  396.                 rts
  397.  
  398.     .term       moveq   #0,d0                           ;terminate
  399.                 rts
  400.  
  401.  
  402.    BUGS
  403.         currently only 68030 is supported
  404.  
  405.    NOTE
  406.         requires ws_Version >= 9
  407.         MUST not be used in public releases, use for development process only
  408.  
  409.    SEE ALSO
  410.         resload_Control
  411.  
  412. WHDLoad/WHDLTAG_CBSWITCH_SET
  413.  
  414.    NAME
  415.         WHDLTAG_CBSWITCH_SET
  416.  
  417.    SYNOPSIS
  418.         to be used with resload_Control
  419.  
  420.         CBSWITCH()
  421.  
  422.    FUNCTION
  423.         using this tag a routine can be set which will executed each time
  424.         WHDLoad switches from the operating system to the installed program
  425.         such a routine is sometimes necessary because during the switch
  426.         between the installed program and the operating system some hardware
  427.         registers are modified by the operating system
  428.         known registers to be modified are cop2lc, bltafwm and bltalwm, maybe
  429.         there are more of them
  430.         the routine must not change any registers, must not use any stack and
  431.         has to return via "jmp (a0)", at execution time of the routine all
  432.         interrupts and dma's are disabled and the memory setup of the
  433.         installed program is active
  434.  
  435.    INPUTS
  436.         pointer to the routine to execute during switch, a value equal 0
  437.         disables the execution of a routine
  438.  
  439.    EXAMPLE
  440.                 ...
  441.                 clr.l   -(a7)                           ;TAG_DONE
  442.                 pea     (_cbswitch,pc)                  ;function
  443.                 move.l  #WHDLTAG_CBSWITCH_SET,-(a7)
  444.                 move.l  a7,a0
  445.                 move.l  (_resload,pc),a2
  446.                 jsr     (resload_Control,a2)
  447.                 lea     (12,a7),a7                      ;restore sp
  448.                 ...
  449.  
  450.      _cbswitch  move.l  (_c2,pc),(_custom+cop2lc)
  451.                 jmp     (a0)
  452.  
  453.      _cb2       dc.l    $10e80
  454.  
  455.    RESULT
  456.         none
  457.  
  458.    BUGS
  459.  
  460.    NOTE
  461.         requires ws_Version >= 7
  462.  
  463.    SEE ALSO
  464.         resload_Control
  465.  
  466. WHDLoad/WHDLTAG_IOERR_GET
  467.  
  468.    NAME
  469.         WHDLTAG_IOERR_GET
  470.  
  471.    SYNOPSIS
  472.         to be used with resload_Control
  473.  
  474.    FUNCTION
  475.         this tag can be used to get the dos errorcode of the last called
  476.         resload function, all resload functions except resload_Control will
  477.         set/reset this error code
  478.         two resload functions are special in that way:
  479.             resload_GetFileSize
  480.                 if a file with the specified name cannot be opened via
  481.                 dos.Open, the error code will be set to the value returned
  482.                 from dos.IoErr, so the error code may contain values like
  483.                 ERROR_OBJECT_NOT_FOUND, ERROR_OBJECT_WRONG_TYPE,
  484.                 ERROR_READ_PROTECTED or similar stuff from dos/dos.i
  485.                 the errorcode can be used to distinguish between a file with
  486.                 size of 0 and a nonexistent file
  487.             resload_ListFiles
  488.                 if the specified buffer to fill is not large enough to hold
  489.                 all filenames from the scanned directory, the error code will
  490.                 be set to ERROR_NO_FREE_STORE
  491.  
  492.    INPUTS
  493.         none
  494.  
  495.    EXAMPLE
  496.                 ...
  497.                 clr.l   -(a7)                           ;TAG_DONE
  498.                 clr.l   -(a7)                           ;data to fill
  499.                 move.l  #WHDLTAG_IOERR_GET,-(a7)
  500.                 move.l  a7,a0
  501.                 move.l  (_resload,pc),a2
  502.                 jsr     (resload_Control,a2)
  503.                 move.l  (4,a7),d0                       ;D0 = IoErr
  504.                 lea     (12,a7),a7                      ;restore sp
  505.                 ...
  506.  
  507.    RESULT
  508.         none
  509.  
  510.    BUGS
  511.  
  512.    NOTE
  513.         requires ws_Version >= 8
  514.  
  515.    SEE ALSO
  516.         resload_Control, resload_GetFileSize, resload_ListFiles
  517.  
  518. WHDLoad/resload_CRC16
  519.  
  520.    NAME
  521.         resload_CRC16 -- calculate ANSI conform 16 bit CRC checksum
  522.  
  523.    SYNOPSIS
  524.         checksum = resload_CRC16(length,address)
  525.            D0                      D0     A0
  526.          UWORD                   ULONG   APTR
  527.  
  528.    FUNCTION
  529.         calculate ANSI conform 16 bit CRC checksum
  530.         mostly used to difference between various program versions
  531.  
  532.    INPUTS
  533.         length  - length of area to calculate over
  534.         address - pointer to area
  535.  
  536.    EXAMPLE
  537.                 ...
  538.                 lea     $1000,a0                ;at address $1000
  539.                 move.l  #256,d0                 ;upto address $1100
  540.                 move.l  (_resload,pc),a2
  541.                 jsr     (resload_CRC16,a2)
  542.                 cmp.w   #$f2b7,d0
  543.                 bne     .false_version
  544.                 ...
  545.  
  546.    RESULT
  547.         checksum - 16 bit crc
  548.  
  549.    BUGS
  550.  
  551.    NOTE
  552.         requires ws_Version >= 3
  553.  
  554.    SEE ALSO
  555.  
  556. WHDLoad/resload_Decrunch
  557.  
  558.    NAME
  559.         resload_Decrunch -- uncompress data in memory
  560.  
  561.    SYNOPSIS
  562.         size = resload_Decrunch(source, destination)
  563.          D0                       A0        A1
  564.         ULONG                    APTR      APTR
  565.  
  566.    FUNCTION
  567.         unpack compressed data in memory, known compressed data formats are
  568.         RNC1, RNC2, IMP!, ATN! and TPWM
  569.         the function first checks if the data source points to is a known
  570.         compressed format, if not it returns with size=0, else the data will
  571.         be unpacked to the destination and the size of the decompressed data
  572.         is returned
  573.         source and destination can be equal, in that case the packed data will
  574.         be overwritten
  575.  
  576.         RNC1:   rob northen compressor - emphasis on packed size, supported is
  577.                 the old and the new format, both formats using the same id but
  578.                 different file formats and compressing algorithms, the
  579.                 function uses some heuristic checks to determinate the correct
  580.                 format, the decompressor for the new common format is highly
  581.                 optimized and contains a routine for 68000/010 and one for
  582.                 68020+, on 68060 it is faster than the IMP! decompressor!
  583.         RNC2:   rob northen compressor - emphasis on unpacking speed, the
  584.                 fastest supported decompressor
  585.         IMP!:   imploder (FImp), the packed data data must not overlap the
  586.                 destinaion for unpacking but the destination must be equal the
  587.                 source or outside the source data, in difference to the
  588.                 original explode routine resload_Decrunch does not destroy the
  589.                 source data (if source is not equal destination)
  590.         ATN!:   identical to IMP! only id is different
  591.         TPWM:   supported starting WHDLoad version 11, because the fileheader
  592.                 does not contain the length of the packed data there is no
  593.                 integrity check
  594.  
  595.         all decompressing routines has been modified to not modify the
  596.         registers A5 and A6 and to use nearly no stack space
  597.         all decompressing routines performing a check if the decompression was
  598.         successful, on a failure the installed program will be terminated and
  599.         WHDLoad will display a message concerning this
  600.  
  601.  
  602.    INPUTS
  603.         source      - address of source in memory
  604.         destination - address of destination in memory (can be equal to source)
  605.  
  606.    EXAMPLE
  607.  
  608.    RESULT
  609.         size - the size of the uncompressed data or 0 if is not compressed
  610.                with a known format
  611.  
  612.    BUGS
  613.  
  614.    NOTE
  615.         the routine performs automatically a resload_FlushCache before
  616.         returning
  617.  
  618.    SEE ALSO
  619.         resload_LoadFileDecrunch
  620.  
  621. WHDLoad/resload_Delay
  622.  
  623.    NAME
  624.         resload_Delay -- wait some time
  625.  
  626.    SYNOPSIS
  627.         resload_Delay(time)
  628.                        D0
  629.                       ULONG
  630.  
  631.    FUNCTION
  632.         wait the specified time or until a button is pressed, all possible
  633.         buttons (LMB, MMB, RMB) of both controllers (port 0/1) are checked,
  634.         after the time runs out or a button is pressed the function waits
  635.         until all buttons has been released
  636.         the wait routine is based on the raster beam, but checks the current
  637.         display and therefore waits the correct time on PAL and NTSC
  638.  
  639.    INPUTS
  640.         time - time to wait in 1/10 seconds
  641.  
  642.    EXAMPLE
  643.                 ...
  644.                 moveq   #30,d0                  ;3 seconds
  645.                 move.l  (_resload,pc),a2
  646.                 jsr     (resload_Delay,a2)
  647.                 ...
  648.  
  649.    RESULT
  650.         nothing, all registers are preserved
  651.  
  652.    BUGS
  653.  
  654.    NOTE
  655.         in difference to most others resload_#? function this routine is
  656.         granted to preserve all registers
  657.         requires ws_Version >= 8
  658.  
  659.    SEE ALSO
  660.  
  661. WHDLoad/resload_Delta
  662.  
  663.    NAME
  664.         resload_Delta -- apply WDelta file
  665.  
  666.    SYNOPSIS
  667.         resload_Delta(src,  dest, delta)
  668.                        A0    A1    A2
  669.                       APTR  APTR  APTR
  670.  
  671.    FUNCTION
  672.         applies the differences provided via delta onto the src and create
  673.         dest
  674.  
  675.    INPUTS
  676.         src   - source data
  677.         dest  - destination memory
  678.         delta - wdelta data
  679.  
  680.    EXAMPLE
  681.                 ...
  682.                 lea     ($10000),a0             ;source
  683.                 lea     ($400),a1               ;destination
  684.                 lea     ($40000),a2             ;wdelta
  685.                 move.l  (_resload,pc),a3
  686.                 jsr     (resload_Delta,a3)
  687.                 ...
  688.  
  689.    RESULT
  690.  
  691.    BUGS
  692.  
  693.    NOTE
  694.         the source and the destination will be crc checked
  695.         if an error occurs WHDLoad will quit with an appropriate requester
  696.         requires ws_Version >= 11
  697.  
  698.    SEE ALSO
  699.  
  700. WHDLoad/resload_DeleteFile
  701.  
  702.    NAME
  703.         resload_Delete -- delete file
  704.  
  705.    SYNOPSIS
  706.         success,errorcode = resload_DeleteFile(name)
  707.           D0       D1                           A0
  708.          BOOL    ULONG                         CPTR
  709.  
  710.    FUNCTION
  711.         deletes the file or directory with the specified name
  712.  
  713.    INPUTS
  714.         name - name of the file/directory to delete
  715.  
  716.    EXAMPLE
  717.                 ...
  718.                 lea     (_name,pc),a0
  719.                 move.l  (_resload,pc),a2
  720.                 jsr     (resload_DeleteFile,a2)
  721.                 ...
  722.  
  723.         _name   dc.b    "C:WHDLoad",0
  724.  
  725.    RESULT
  726.         success   - TRUE on success
  727.         errorcode - 0 on success
  728.                     otherwise a dos-errorcode from dos.IoErr()
  729.         if WHDLF_NoError is set, the function only returns on success
  730.  
  731.    BUGS
  732.  
  733.    NOTE
  734.         requires ws_Version >= 8
  735.  
  736.    SEE ALSO
  737.  
  738. WHDLoad/resload_DiskLoad
  739.  
  740.    NAME
  741.         resload_DiskLoad -- load part from a diskimage
  742.  
  743.    SYNOPSIS
  744.         success,errorcode = resload_DiskLoad(offset,size,diskno,dest)
  745.           D0       D1                          D0    D1    D2    A0
  746.          BOOL    ULONG                        ULONG ULONG UBYTE APTR
  747.  
  748.    FUNCTION
  749.         load part from a diskimage
  750.  
  751.    INPUTS
  752.         offset - offset in diskimage (relative to the beginning)
  753.         size   - amount of bytes to read
  754.         diskno - disk number
  755.         dest   - destination address
  756.  
  757.    EXAMPLE
  758.                 ...
  759.                 move.l  #880*512,d0             ;from block 880
  760.                 move.l  #2*512,d1               ;2 blocks
  761.                 moveq   #1,d2                   ;disk 1
  762.                 lea     $80000,a0               ;destination
  763.                 move.l  (_resload,pc),a2
  764.                 jsr     (resload_LoadDisk,a2)
  765.                 ...
  766.  
  767.    RESULT
  768.         success   - TRUE on success
  769.         errorcode - 0 on success
  770.                     otherwise a dos-errorcode from dos.IoErr()
  771.         if WHDLF_NoError is set, the function only returns on success
  772.  
  773.    BUGS
  774.  
  775.    NOTE
  776.         the name of the disk images must be "disk." followed by the disk
  777.         number (i.e. "Disk.1")
  778.         the size of the diskimages is variable, an attempt to read data
  779.         outside the disk image will result in a seek error
  780.         the routine performs automatically a resload_FlushCache before
  781.         returning
  782.  
  783.    SEE ALSO
  784.         resload_LoadFileOffset
  785.  
  786. WHDLoad/resload_DiskLoadDev
  787.  
  788.    NAME
  789.         resload_DiskLoadDev -- load part from a floppy disk
  790.  
  791.    SYNOPSIS
  792.         success,errorcode = resload_DiskLoadDev(offset, size,  dest,  tags)
  793.           D0       D1                             D0     D1     A0     A1
  794.          BOOL    ULONG                          ULONG  ULONG  UBYTE  STRUCT
  795.  
  796.    FUNCTION
  797.         load a given amount of bytes from a floppy like device
  798.  
  799.    INPUTS
  800.         offset - offset on the disk (relative to the beginning)
  801.         size   - amount of bytes to read (at the moment this must be a
  802.                  multiple of 512 bytes)
  803.         dest   - destination address (at the moment this must be aligned
  804.                  to 512 bytes)
  805.         tags   - pointer to a taglist (at the moment there are no valid
  806.                  tags, so this must be NULL)
  807.  
  808.    EXAMPLE
  809.                 ...
  810.                 move.l  #880*512,d0             ;from block 880
  811.                 move.l  #2*512,d1               ;2 blocks
  812.                 lea     $80000,a0               ;destination
  813.                 sub.l   a1,a1                   ;tag list
  814.                 move.l  (_resload,pc),a2
  815.                 jsr     (resload_LoadDisk,a2)
  816.                 ...
  817.  
  818.    RESULT
  819.         success   - TRUE on success
  820.         errorcode - 0 on success
  821.                     otherwise a trackdisk errorcode
  822.         if WHDLF_NoError is set, the function only returns on success
  823.  
  824.    BUGS
  825.  
  826.    NOTE
  827.         requires ws_Version >= 2
  828.         at the moment all (size, address) must be aligned to 512 bytes due
  829.         restrictions of trackdisk.device
  830.         the routine performs automatically a resload_FlushCache before
  831.         returning
  832.  
  833.    SEE ALSO
  834.  
  835. WHDLoad/resload_FlushCache
  836.  
  837.    NAME
  838.         resload_FluchCache -- clear CPU caches
  839.  
  840.    SYNOPSIS
  841.         resload_FlushCache()
  842.  
  843.    FUNCTION
  844.         clear all CPU caches
  845.  
  846.    INPUTS
  847.  
  848.    EXAMPLE
  849.  
  850.    RESULT
  851.  
  852.    BUGS
  853.  
  854.    NOTE
  855.         in difference to most others resload_#? function this routine is
  856.         granted to preserve all registers
  857.         it is safe to call this routine from User or Supervisor mode and
  858.         independend from the actual CPU type (also on 68000/010)
  859.         it uses the CACR on 68020/030 and a "cpusha bc" on 68040/060
  860.  
  861.    SEE ALSO
  862.         resload_SetCPU
  863.  
  864. WHDLoad/resload_GetFileSize
  865.  
  866.    NAME
  867.         resload_GetFileSize -- get size of a file
  868.  
  869.    SYNOPSIS
  870.         size = resload_GetFileSize(name)
  871.          D0                         A0
  872.         ULONG                      CPTR
  873.  
  874.    FUNCTION
  875.         get size of a file, or check if a file exists
  876.         to distinguish between a file with a size of 0 and an nonexisting
  877.         file the tag WHDLTAG_IOERR_GET must be used in conjunction with
  878.         resload_Control
  879.  
  880.    INPUTS
  881.         name - name of the file to get size from
  882.  
  883.    EXAMPLE
  884.                 ...
  885.                 lea     (_filename,pc),a0
  886.                 move.l  (_resload,pc),a2
  887.                 jsr     (resload_GetFileSize,a2)
  888.                 tst.l   d0
  889.                 beq     .file_not_exist
  890.                 ...
  891.  
  892.    RESULT
  893.         size - the size of the file, 0 if does not exist
  894.  
  895.    BUGS
  896.  
  897.    NOTE
  898.         this routine returns the filesize obtained by the filesystem, if the
  899.         file is compressed and is loaded later via resload_LoadFileDecrunch
  900.         the loaded filesize will differ!
  901.  
  902.    SEE ALSO
  903.         resload_Control, resload_GetFileSizeDec, resload_LoadFile,
  904.         resload_LoadFileDecrunch
  905.  
  906. WHDLoad/resload_GetFileSizeDec
  907.  
  908.    NAME
  909.         resload_GetFileSizeDec -- get size of a packed file
  910.  
  911.    SYNOPSIS
  912.         size = resload_GetFileSizeDec (name)
  913.          D0                         A0
  914.         ULONG                      CPTR
  915.  
  916.    FUNCTION
  917.         get size of a packed file, or check if a file exists
  918.         the routine knows the same decruncher that resload_Decrunch supports
  919.         to distinguish between a file with a size of 0 and an nonexisting
  920.         file the tag WHDLTAG_IOERR_GET must be used in conjunction with
  921.         resload_Control
  922.  
  923.    INPUTS
  924.         name - name of the file to get size from
  925.  
  926.    EXAMPLE
  927.                 ...
  928.                 lea     (_filename,pc),a0
  929.                 move.l  (_resload,pc),a2
  930.                 jsr     (resload_GetFileSizeDec,a2)
  931.                 tst.l   d0
  932.                 bne     .file_not_exist
  933.                 ...
  934.  
  935.    RESULT
  936.         size - the size of the file, 0 if does not exist
  937.  
  938.    BUGS
  939.  
  940.    NOTE
  941.  
  942.    SEE ALSO
  943.         resload_Control, resload_GetFileSize, resload_LoadFile,
  944.         resload_LoadFileDecrunch
  945.  
  946. WHDLoad/resload_ListFiles
  947.  
  948.    NAME
  949.         resload_ListFiles -- list filenames of a directory
  950.  
  951.    SYNOPSIS
  952.         amount,errorcode = resload_ListFiles(buffersize, name, buffer)
  953.           D0      D1                             D0       A0     A1
  954.         ULONG   ULONG                          ULONG     CPTR   APTR
  955.  
  956.    FUNCTION
  957.         writes the names of all files in the specified directory to the
  958.         buffer, the file names are separated with a $0 character
  959.         only files are listed, directories are skipped
  960.         if the buffer to fill is not large enough to hold all file names the
  961.         routine fills it as far as possible, the tag WHDLTAG_IOERR_GET in
  962.         conjunction with resload_Control can be used to check if all file
  963.         names have fit into the buffer
  964.  
  965.  
  966.    INPUTS
  967.         buffersize - the size of the buffer
  968.         name       - the name of the directory to scan
  969.         buffer     - pointer to the buffer (the buffer must be located inside
  970.                      the Slave)
  971.  
  972.    EXAMPLE
  973.                 ...
  974.                 move.l  #_bufend-_buf,d0
  975.                 lea     (_savepath,pc),a0
  976.                 lea     (_buf,pc),a1
  977.                 move.l  (_resload,pc),a2
  978.                 jsr     (resload_ListFiles,a2)
  979.                 ...
  980.  
  981.         _buf      ds.b    1000
  982.         _bufend
  983.         _savepath dc.b  "/save",0       ;this must be a relative path!
  984.  
  985.  
  986.    RESULT
  987.         amount    - amount of listed files in the buffer
  988.         errorcode - 0 on success
  989.                     otherwise a dos-errorcode from dos.IoErr()
  990.         if WHDLF_NoError is set, the function only returns on success
  991.  
  992.    BUGS
  993.  
  994.    NOTE
  995.  
  996.    SEE ALSO
  997.         resload_Control
  998.  
  999. WHDLoad/resload_LoadFile
  1000.  
  1001.    NAME
  1002.         resload_LoadFile -- load file into memory
  1003.  
  1004.    SYNOPSIS
  1005.         length,errorcode = resload_LoadFile(name, address)
  1006.           D0      D1                         A0      A1
  1007.         ULONG    ULONG                      CPTR    APTR
  1008.  
  1009.    FUNCTION
  1010.         load file to the specified memory address
  1011.  
  1012.    INPUTS
  1013.         name    - name of the file to load
  1014.         address - memory address to load the file on
  1015.  
  1016.    EXAMPLE
  1017.                 ...
  1018.                 lea     (_filename),a0          ;name
  1019.                 lea     $1000.w,a1              ;destination
  1020.                 move.l  (_resload,pc),a2
  1021.                 jsr     (resload_LoadFile,a2)
  1022.                 ...
  1023.  
  1024.    RESULT
  1025.         length    - the size of the loaded file, or 0 on error
  1026.         errorcode - 0 on success
  1027.                     otherwise a dos-errorcode from dos.IoErr()
  1028.         if WHDLF_NoError is set, the function only returns on success
  1029.  
  1030.    BUGS
  1031.  
  1032.    NOTE
  1033.         the routine performs automatically a resload_FlushCache before
  1034.         returning
  1035.  
  1036.    SEE ALSO
  1037.         resload_LoadFileDecrunch, resload_LoadFileOffset
  1038.  
  1039. WHDLoad/resload_LoadFileDecrunch
  1040.  
  1041.    NAME
  1042.         resload_LoadFileDecrunch -- load file and uncompress
  1043.  
  1044.    SYNOPSIS
  1045.         length,errorcode = resload_LoadFileDecrunch(name, address)
  1046.           D0      D1                                 A0      A1
  1047.         ULONG    ULONG                              CPTR    APTR
  1048.  
  1049.    FUNCTION
  1050.         loads the specified file into memory and unpack it if it is in a
  1051.         supported compressed data format
  1052.         using this routine instead of resload_LoadFile easily allows it to add
  1053.         support for compressed data files to a installed program, the
  1054.         decompression is absolutely transparent, so the installed program will
  1055.         not detect if the files loaded are compressed on disk or not, the only
  1056.         thing which must be considered is that files that are written using
  1057.         resload_SaveFileOffset or loaded via resload_LoadFileOffset must not
  1058.         be compressed
  1059.  
  1060.    INPUTS
  1061.         name    - name of file to load
  1062.         address - memory address to load the file on
  1063.  
  1064.    EXAMPLE
  1065.                 ...
  1066.                 lea     (_filename),a0          ;name
  1067.                 lea     $1000.w,a1              ;destination
  1068.                 move.l  (_resload,pc),a2
  1069.                 jsr     (resload_LoadFileDecrunch,a2)
  1070.                 ...
  1071.  
  1072.    RESULT
  1073.         length    - the size of the loaded file
  1074.                     if an error occurs this is 0
  1075.         errorcode - 0 on success
  1076.                     otherwise a dos-errorcode from dos.IoErr()
  1077.         if WHDLF_NoError is set, the function only returns on success
  1078.  
  1079.    BUGS
  1080.  
  1081.    NOTE
  1082.         the routine performs automatically a resload_FlushCache before
  1083.         returning
  1084.  
  1085.    SEE ALSO
  1086.         resload_Decrunch, resload_LoadFile, resload_LoadFileOffset,
  1087.         resload_SaveFile, resload_SaveFileOffset
  1088.  
  1089. WHDLoad/resload_LoadFileOffset
  1090.  
  1091.    NAME
  1092.         resload_LoadFileOffset -- load data inside a file to memory
  1093.  
  1094.    SYNOPSIS
  1095.         success,error = resload_LoadFileOffset(size, offset, name, address)
  1096.           D0     D1                             D0     D1     A0      A1
  1097.          BOOL   ULONG                          ULONG  ULONG  CPTR    APTR
  1098.  
  1099.    FUNCTION
  1100.         load a part of a file into memory, the part of the file is specified
  1101.         by an offset in the file and a byte count to read, the routine is
  1102.         nearly identical to resload_DiskLoad but instead of specifying the
  1103.         number of the disk to read from a filename is used to select the file
  1104.  
  1105.    INPUTS
  1106.         size    - amount of bytes to read
  1107.         offset  - offset in the file
  1108.         name    - name of file
  1109.         address - memory address to load the file on
  1110.  
  1111.    EXAMPLE
  1112.                 ...
  1113.                 move.l  #512,d0                 ;size
  1114.                 move.l  #$4000,d1               ;offset
  1115.                 lea     (_save,pc),a0           ;name
  1116.                 lea     $5ac20,a1               ;source
  1117.                 move.l  (_resload,pc),a2
  1118.                 jsr     (resload_LoadFileOffset,a2)
  1119.                 ...
  1120.  
  1121.         _save   dc.b    "saved",0
  1122.  
  1123.    RESULT
  1124.         success   - TRUE on success
  1125.         errorcode - 0 on success
  1126.                     otherwise a dos-errorcode from dos.IoErr()
  1127.         if WHDLF_NoError is set, the function only returns on success
  1128.  
  1129.    BUGS
  1130.  
  1131.    NOTE
  1132.         the routine performs automatically a resload_FlushCache before
  1133.         returning
  1134.         requires ws_Version >= 6
  1135.  
  1136.    SEE ALSO
  1137.         resload_DiskLoad, resload_LoadFile
  1138.  
  1139. WHDLoad/resload_LoadKick
  1140.  
  1141.    NAME
  1142.         resload_LoadKick -- load kickstart image
  1143.  
  1144.    SYNOPSIS
  1145.         resload_LoadKick(size, crc16,  name)
  1146.                           D0     D1     A0
  1147.                          ULONG  UWORD  CPTR
  1148.  
  1149.    FUNCTION
  1150.         load kickstart image with the specified name into ExpMem
  1151.  
  1152.    INPUTS
  1153.         size    - size of kickstart image
  1154.         crc16   - CRC16 of kickstart image
  1155.         name    - basename of kickstart image
  1156.  
  1157.    EXAMPLE
  1158.                 ...
  1159.                 move.l  #$40000,d0              ;size
  1160.                 move.w  #$f20b,d1               ;crc16
  1161.                 lea     (_kick,pc),a0           ;name
  1162.                 move.l  (_resload,pc),a2
  1163.                 jsr     (resload_LoadKick,a2)
  1164.                 ...
  1165.  
  1166.         _kick   dc.b    "34005.a500",0
  1167.  
  1168.    RESULT
  1169.  
  1170.    BUGS
  1171.  
  1172.    NOTE
  1173.         requires ws_Version >= 11
  1174.  
  1175.    SEE ALSO
  1176.  
  1177. WHDLoad/resload_Patch
  1178.  
  1179.    NAME
  1180.         resload_Patch -- apply patchlist
  1181.  
  1182.    SYNOPSIS
  1183.         resload_Patch(patchlist, destination)
  1184.                          A0          A1
  1185.                         APTR        APTR
  1186.  
  1187.    FUNCTION
  1188.         modify memory using commands from a specified patch list,
  1189.         to make an installed program working under WHDLoad it must be patched,
  1190.         that means the program must be modified so that it will load data via
  1191.         WHDLoad instead of using its own loader routines, often also various
  1192.         other things must be changed to make it working
  1193.         the modifying of the installed program can be done using this routine,
  1194.         a patch list will be build by using macros from the include file
  1195.         "whdpatch.i", each entry in the patchlist specifies a command to
  1196.         perform, an address to apply the command on and optional extra data,
  1197.         resload_Patch is especially useful if the memory to modify is located
  1198.         in the ExpMem and therefore the destination address in only know at
  1199.         runtime and not at creation time of the Slave
  1200.  
  1201.    INPUTS
  1202.         patchlist   - list of commands describing the patches to apply
  1203.         destination - address of memory region to patch
  1204.  
  1205.    EXAMPLE
  1206.                 ...
  1207.                 lea     (_pl,pc),a0             ;patchlist
  1208.                 move.l  (_expmem,pc),a1         ;destination
  1209.                 move.l  (_resload,pc),a2
  1210.                 jsr     (resload_Patch,a2)
  1211.                 ...
  1212.  
  1213.         _pl     PL_START
  1214.                 PL_P    $560,_loadfile          ;the loading routine
  1215.                 PL_R    $2046                   ;copylock
  1216.                 PL_END
  1217.  
  1218.    RESULT
  1219.  
  1220.    BUGS
  1221.  
  1222.    NOTE
  1223.         the routine performs automatically a resload_FlushCache before
  1224.         returning
  1225.         requires ws_Version >= 10
  1226.  
  1227.    SEE ALSO
  1228.  
  1229. WHDLoad/resload_ProtectRead
  1230.  
  1231.    NAME
  1232.         resload_ProtectRead -- mark memory as read protected
  1233.  
  1234.    SYNOPSIS
  1235.         resload_ProtectRead(length, address)
  1236.                               D0      A0
  1237.                              ULONG   APTR
  1238.  
  1239.    FUNCTION
  1240.         protect the specified memory against reading by the processor
  1241.         the memory to protect must be located inside BaseMem or ExpMem
  1242.  
  1243.    INPUTS
  1244.         length  - size of the memory area to protected
  1245.         address - start address of the memory area to protected
  1246.  
  1247.    EXAMPLE
  1248.                 ...
  1249.                 moveq   #4,d0                   ;one longword
  1250.                 lea     $4070,a0                ;address
  1251.                 move.l  (_resload,pc),a2
  1252.                 jsr     (resload_ProtectRead,a2)
  1253.                 ...
  1254.  
  1255.    RESULT
  1256.         a "Exception 'Access Fault'" WHDLoad requester if the protected memory
  1257.         is accessed
  1258.  
  1259.    BUGS
  1260.         the amount of protected areas is currently limited to 16,
  1261.         the page where the SSP points to must not be protected, because if a
  1262.         Access Fault occurs the CPU will be unable in that case to write the
  1263.         exception stackframe, only reset will recover from the resulting
  1264.         Double Bus Fault
  1265.         limitations on MC68020+MC68851:
  1266.           this hardware is currently not supported
  1267.         limitations on MC68030:
  1268.           - 3-byte transfers are not supported (occuring on misaligned
  1269.             longword accesses to page boundaries eg. "tst.l $fff" (assumed
  1270.             4KByte page size))
  1271.           - locked accesses (tas/cas/cas2) are not supported
  1272.         limitations on MC68040:
  1273.           this hardware is currently not supported
  1274.         limitations on MC68060:
  1275.           - misaligned access are not supported (occuring on accesses trough a
  1276.             page boundary, for example "tst.l ($ffe)" (assumed 4KByte page
  1277.             size))
  1278.           - locked accesses (tas/cas) are not supported
  1279.           - instructions which are located on a protected page and access the
  1280.             supervisor portion of the status register will be executed wrong
  1281.             (these instructions will always see the trace bit as 1 and the
  1282.             interrupt level as 7, any modification of the status register
  1283.             supervisor portion will be without effect)
  1284.           - movem instruction may access a protected area without creating a
  1285.             Access Fault exception (only the first bus cycle of the excution
  1286.             unit will be verified for matching a protected area)
  1287.           - move16 and double precision operations (FPU) are unsupported
  1288.           - a "move (mem),(mem)" with overlapping source and destination
  1289.             address which generates an Access Fault because Misalignment
  1290.             will be executed wrong, for example "move.l ($ffc),($ffe)" where
  1291.             page $1000..$1fff is protected and memory before execution
  1292.             contains ($ffc)=$11112222,($1000)=$33334444, after execution
  1293.             $1000 contains $11114444 and not $22224444)
  1294.         unsupported accesses will result in a "Exception 'Access Fault'"
  1295.         WHDLoad requester
  1296.  
  1297.    NOTE
  1298.         requires ws_Version >= 6
  1299.         the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
  1300.         requester "Unacceptible Arguments".
  1301.         only accesses to the user and supervisor data stream are affected
  1302.         (this means not affected are: CPU space accesses (eg getting values
  1303.         from the vector table) and instruction stream accesses)
  1304.  
  1305.    SEE ALSO
  1306.         resload_ProtectReadWrite, resload_ProtectWrite, resload_ProtectRemove
  1307.  
  1308. WHDLoad/resload_ProtectReadWrite
  1309.  
  1310.    NAME
  1311.         resload_ProtectReadWrite -- mark memory as read and write protected
  1312.  
  1313.    SYNOPSIS
  1314.         resload_ProtectReadWrite(length, address)
  1315.                                    D0      A0
  1316.                                   ULONG   APTR
  1317.  
  1318.    FUNCTION
  1319.         protect the specified memory against reading and writing by the
  1320.         processor
  1321.         the memory to protect must be located inside BaseMem or ExpMem
  1322.  
  1323.    INPUTS
  1324.         length  - size of the memory area to protected
  1325.         address - start address of the memory area to protected
  1326.  
  1327.    EXAMPLE
  1328.                 ...
  1329.                 moveq   #4,d0                   ;one longword
  1330.                 lea     $64,a0                  ;address
  1331.                 move.l  (_resload,pc),a2
  1332.                 jsr     (resload_ProtectReadWrite,a2)
  1333.                 ...
  1334.  
  1335.    RESULT
  1336.         a "Exception 'Access Fault'" WHDLoad requester if the protected memory
  1337.         is accessed
  1338.  
  1339.    BUGS
  1340.         the amount of protected areas is currently limited to 16,
  1341.         the page where the SSP points to must not be protected, because if a
  1342.         Access Fault occurs the CPU will be unable in that case to write the
  1343.         exception stackframe, only reset will recover from the resulting
  1344.         Double Bus Fault
  1345.         limitations on MC68020+MC68851:
  1346.           this hardware is currently not supported
  1347.         limitations on MC68030:
  1348.           - 3-byte transfers are not supported (occuring on misaligned
  1349.             longword accesses to page boundaries eg. "tst.l $fff" (assumed
  1350.             4KByte page size))
  1351.           - locked accesses (tas/cas/cas2) are not supported
  1352.         limitations on MC68040:
  1353.           this hardware is currently not supported
  1354.         limitations on MC68060:
  1355.           - misaligned access are not supported (occuring on accesses trough a
  1356.             page boundary, for example "tst.l ($ffe)" (assumed 4KByte page
  1357.             size))
  1358.           - locked accesses (tas/cas) are not supported
  1359.           - instructions which are located on a protected page and access the
  1360.             supervisor portion of the status register will be executed wrong
  1361.             (these instructions will always see the trace bit as 1 and the
  1362.             interrupt level as 7, any modification of the status register
  1363.             supervisor portion will be without effect)
  1364.           - movem instruction may access a protected area without creating a
  1365.             Access Fault exception (only the first bus cycle of the excution
  1366.             unit will be verified for matching a protected area)
  1367.           - move16 and double precision operations (FPU) are unsupported
  1368.           - a "move (mem),(mem)" with overlapping source and destination
  1369.             address which generates an Access Fault because Misalignment
  1370.             will be executed wrong, for example "move.l ($ffc),($ffe)" where
  1371.             page $1000..$1fff is protected and memory before execution
  1372.             contains ($ffc)=$11112222,($1000)=$33334444, after execution
  1373.             $1000 contains $11114444 and not $22224444)
  1374.         unsupported accesses will result in a "Exception 'Access Fault'"
  1375.         WHDLoad requester
  1376.  
  1377.    NOTE
  1378.         requires ws_Version >= 6
  1379.         the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
  1380.         requester "Unacceptible Arguments".
  1381.         only accesses to the user and supervisor data stream are affected
  1382.         (this means not affected are: CPU space accesses (eg getting values
  1383.         from the vector table) and instruction stream accesses)
  1384.  
  1385.    SEE ALSO
  1386.         resload_ProtectRead, resload_ProtectWrite, resload_ProtectRemove
  1387.  
  1388. WHDLoad/resload_ProtectRemove
  1389.  
  1390.    NAME
  1391.         resload_ProtectRemove -- remove protection from memory area
  1392.  
  1393.    SYNOPSIS
  1394.         resload_ProtectRemove(length, address)
  1395.                                 D0      A0
  1396.                                ULONG   APTR
  1397.  
  1398.    FUNCTION
  1399.         remove a previously created protection
  1400.         the specified area must exactly match the previously protected area
  1401.  
  1402.    INPUTS
  1403.         length  - size of the memory area to protected
  1404.         address - start address of the memory area to protected
  1405.  
  1406.    EXAMPLE
  1407.                 ...
  1408.                 moveq   #4,d0                   ;one longword
  1409.                 lea     $64,a0                  ;address
  1410.                 move.l  (_resload,pc),a2
  1411.                 jsr     (resload_ProtectRemove,a2)
  1412.                 ...
  1413.  
  1414.    RESULT
  1415.  
  1416.    BUGS
  1417.  
  1418.    NOTE
  1419.         requires ws_Version >= 6
  1420.  
  1421.    SEE ALSO
  1422.         resload_ProtectRead, resload_ProtectWrite, resload_ProtectWrite
  1423.  
  1424. WHDLoad/resload_ProtectSMC
  1425.  
  1426.    NAME
  1427.         resload_ProtectSMC -- detect self modifying code
  1428.  
  1429.    SYNOPSIS
  1430.         resload_ProtectSMC(length, address)
  1431.                              D0      A0
  1432.                             ULONG   APTR
  1433.  
  1434.    FUNCTION
  1435.         Enables automatically detection of self modifying code (SMC) in the
  1436.         selected area. The selected area will be write protected using the
  1437.         resload_ProtectWrite mechanism, additional the trace mode will be
  1438.         activated and a special handler for trace exceptions installed.
  1439.         Each write access to the selected area will be logged to a private
  1440.         memory location. On each instruction executed inside the selected
  1441.         memory the trace handler verifies, if the instruction has been
  1442.         previosly modified. If an executed instruction has been altered
  1443.         the installed program will be terminated and WHDLoad will show an
  1444.         requester informing about the SMC-detection.
  1445.         To determinate the size of instructions a table is used. This table
  1446.         contains the opcode size in words depending on the first instruction
  1447.         word. If the trace exception handler encounters a instruction with
  1448.         unknown size WHDLoad aborts with an "Internal Error #3". The reason
  1449.         for this maybe an illegal instruction, an instruction available only
  1450.         in higher processors than 68000 or an incompleteness of the internal
  1451.         instruction size table (IST). To aid this, during the initialisation
  1452.         of this function WHDLoad searches first for an external IST. This
  1453.         must be located in the same directory where the WHDLoad executable
  1454.         resides and is searched as "PROGDIR:WHDLoad.IST". If there is no
  1455.         external IST the internal one is used. The source of the internal
  1456.         IST is included in source representation and can be used to build a
  1457.         external IST. If you encounter missing 68000 instructions in the
  1458.         current IST you are demand to inform the author of WHDLoad to
  1459.         include appropriate extensions in the next WHDLoad release.
  1460.         Due the large exception overhead the execution speed in the selected
  1461.         area will strongly slow down. To improve performance it is therefore
  1462.         recommend to relocate the SSP to a Fast-Memory location using
  1463.         ws_ExpMem and appropriate initialistion and modification of the
  1464.         installed program if required.
  1465.         To maximize performance during the initialisation of this function
  1466.         the BaseMem area will be set to NC, the ExpMem and Slave to CB and
  1467.         all caches will be enabled (resload_SetCPU).
  1468.         Because Resload functions cannot be executed in trace mode, the
  1469.         trace must disabled before and enabled after calling any Resload
  1470.         function following the SMC-detection has been setup (see example).
  1471.  
  1472.  
  1473.    INPUTS
  1474.         length  - size of the memory area to protect
  1475.         address - start address of the memory area to protect
  1476.  
  1477.         the area to protect must be located inside the BaseMem or ExpMem
  1478.  
  1479.    EXAMPLE
  1480.  
  1481.         enable SMC-detection for the area $10000..$3e000:
  1482.                 ...
  1483.                 move.l  #$2e000,d0              ;length
  1484.                 lea     $10000,a0               ;address
  1485.                 move.l  (_resload,pc),a2
  1486.                 jsr     (resload_ProtectSMC,a2)
  1487.                 ...
  1488.  
  1489.         load data after enabling the SMC-detection (assumed all time in
  1490.         supervisor mode!):
  1491.                 ...
  1492.                 move    sr,d3                   ;save sr
  1493.                 move    #$2000,sr               ;disable trace mode
  1494.                 move.l  (_resload,pc),a2
  1495.                 jsr     (resload_DiskLoad,a2)
  1496.                 move    d3,sr                   ;restore sr
  1497.                 ...
  1498.  
  1499.    RESULT
  1500.  
  1501.    BUGS
  1502.         Currently supported is only 68030 and 68060. For limitations and
  1503.         restrictions regarding the MMU related part of operation see the BUGS
  1504.         section of resload_ProtectWrite.
  1505.         You must not protect the page where the SSP points to, if you do so
  1506.         an Double Bus Fault will occure because the CPU will be unable to
  1507.         write the exception stackframe, only reset will recover from a Double
  1508.         Bus Fault
  1509.  
  1510.    NOTE
  1511.         requires ws_Version >= 10
  1512.         the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
  1513.         requester "Unacceptible Arguments"
  1514.         there must be no resload_Protect* active at the same time
  1515.  
  1516.    SEE ALSO
  1517.         resload_ProtectWrite, resload_SetCPU
  1518.  
  1519. WHDLoad/resload_ProtectWrite
  1520.  
  1521.    NAME
  1522.         resload_ProtectWrite -- mark memory as write protected
  1523.  
  1524.    SYNOPSIS
  1525.         resload_ProtectWrite(length, address)
  1526.                                D0      A0
  1527.                               ULONG   APTR
  1528.  
  1529.    FUNCTION
  1530.         protect the selected area against writing by the processor
  1531.         the area to protect must be located inside BaseMem or ExpMem
  1532.  
  1533.    INPUTS
  1534.         length  - size of the memory area to protected
  1535.         address - start address of the memory area to protected
  1536.  
  1537.    EXAMPLE
  1538.                 ...
  1539.                 moveq   #4,d0                   ;one longword
  1540.                 lea     $64,a0                  ;address
  1541.                 move.l  (_resload,pc),a2
  1542.                 jsr     (resload_ProtectWrite,a2)
  1543.                 ...
  1544.  
  1545.    RESULT
  1546.  
  1547.    BUGS
  1548.         the amount of protected areas is currently limited to 16,
  1549.         the page where the SSP points to must not be protected, because if a
  1550.         Access Fault occurs the CPU will be unable in that case to write the
  1551.         exception stackframe, only reset will recover from the resulting
  1552.         Double Bus Fault
  1553.         limitations on MC68020+MC68851:
  1554.           this hardware is currently not supported
  1555.         limitations on MC68030:
  1556.           - 3-byte transfers are not supported (occuring on misaligned
  1557.             longword accesses to page boundaries eg. "tst.l $fff" (assumed
  1558.             4KByte page size))
  1559.           - locked accesses (tas/cas/cas2) are not supported
  1560.         limitations on MC68040:
  1561.           this hardware is currently not supported
  1562.         limitations on MC68060:
  1563.           - misaligned access are not supported (occuring on accesses trough a
  1564.             page boundary, for example "tst.l ($ffe)" (assumed 4KByte page
  1565.             size))
  1566.           - locked accesses (tas/cas) are not supported
  1567.           - instructions which are located on a protected page and access the
  1568.             supervisor portion of the status register will be executed wrong
  1569.             (these instructions will always see the trace bit as 1 and the
  1570.             interrupt level as 7, any modification of the status register
  1571.             supervisor portion will be without effect)
  1572.           - movem instruction may access a protected area without creating a
  1573.             Access Fault exception (only the first bus cycle of the excution
  1574.             unit will be verified for matching a protected area)
  1575.           - move16 and double precision operations (FPU) are unsupported
  1576.           - a "move (mem),(mem)" with overlapping source and destination
  1577.             address which generates an Access Fault because Misalignment
  1578.             will be executed wrong, for example "move.l ($ffc),($ffe)" where
  1579.             page $1000..$1fff is protected and memory before execution
  1580.             contains ($ffc)=$11112222,($1000)=$33334444, after execution
  1581.             $1000 contains $11114444 and not $22224444)
  1582.         unsupported accesses will result in a "Exception 'Access Fault'"
  1583.         WHDLoad requester
  1584.  
  1585.    NOTE
  1586.         requires ws_Version >= 6
  1587.         the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
  1588.         requester "Unacceptible Arguments".
  1589.         only accesses to the user and supervisor data stream are affected
  1590.         (this means not affected are: CPU space accesses (eg getting values
  1591.         from the vector table) and instruction stream accesses)
  1592.  
  1593.    SEE ALSO
  1594.         resload_ProtectRead, resload_ProtectReadWrite, resload_ProtectRemove
  1595.  
  1596. WHDLoad/resload_Relocate
  1597.  
  1598.    NAME
  1599.         resload_Relocate -- relocate AmigaDOS executable
  1600.  
  1601.    SYNOPSIS
  1602.         size = resload_Relocate(address, tags)
  1603.          D0                       A0      A1
  1604.         ULONG                    APTR   STRUCT
  1605.  
  1606.    FUNCTION
  1607.         relocate an standard AmigaDOS executable in memory
  1608.  
  1609.    INPUTS
  1610.         address - the start address of the executable in memory, this is the
  1611.                   source and also the destination address, i.e.
  1612.                   resload_Relocate will relocates the executable over itself
  1613.                   (a multi pass technique is used)
  1614.         tags    - there are two valid tags starting WHDLoad version 14.1
  1615.                   WHDLTAG_CHIPPTR - specifies a extra memory location where
  1616.                     to put hunks with the memory flag MEMF_CHIP
  1617.                   WHDLTAG_FASTPTR - specifies a extra memory location where
  1618.                     to put hunks with the memory flag MEMF_FAST
  1619.                   the different memory locations must not overlap, WHDLoad
  1620.                   will check that and report 'illegal args' if they do
  1621.  
  1622.    EXAMPLE
  1623.                 ...
  1624.                 lea     (_main,pc),a0           ;name
  1625.                 lea     $400,a3                 ;A3 = address for program
  1626.                 move.l  a3,a1                   ;destination
  1627.                 move.l  (_resload,pc),a2
  1628.                 jsr     (resload_LoadFileDecrunch,a2)
  1629.                 move.l  a3,a0                   ;address
  1630.                 sub.l   a1,a1                   ;tags
  1631.                 jsr     (resload_Relocate,a2)
  1632.                 ...
  1633.                 jmp     (a3)                    ;start the program
  1634.                 ...
  1635.  
  1636.         _main   dc.b    "main-program",0
  1637.  
  1638.    EXAMPLE
  1639.                 ...
  1640.                 move.l  (_freefast),a0          ;address
  1641.                 clr.l   -(a7)                   ;TAG_DONE
  1642.                 move.l  (_freechip),-(a7)       ;chip area
  1643.                 pea     WHDLTAG_CHIPPTR
  1644.                 move.l  a7,a1                   ;tags
  1645.                 move.l  (_resload,pc),a2
  1646.                 jsr     (resload_Relocate,a2)
  1647.                 add.l   d0,(_freefast)
  1648.                 add.l   (4,a7),(_freechip)
  1649.                 add.w   #12,a7
  1650.                 ...
  1651.  
  1652.    RESULT
  1653.         size - size of the relocated executable
  1654.                (this may be more or less than the size of the executable file,
  1655.                depending on BSS hunks contained in the executable)
  1656.         tags - the ti_Data field will be overwritten with the length of data
  1657.                stored in this area
  1658.  
  1659.    BUGS
  1660.         the routine supports all hunks supported by Kickstart 1.3 except
  1661.         OVERLAY, anyway it is only tested with a limited amount of
  1662.         executables, so please report any problems or bugs
  1663.  
  1664.    NOTE
  1665.         the function uses stack for variables, the amount depends on the
  1666.         number of hunks in the executable and can be calculated as
  1667.         "used stack = hunks * 16 + 32"
  1668.         currently the executable must not contain more than 256 hunks (also
  1669.         AmigaDOS allows not more than 256 hunks)
  1670.         the routine performs automatically a resload_FlushCache before
  1671.         returning
  1672.  
  1673.    SEE ALSO
  1674.  
  1675. WHDLoad/resload_SaveFile
  1676.  
  1677.    NAME
  1678.         resload_SaveFile -- write memory to a file
  1679.  
  1680.    SYNOPSIS
  1681.         success,errorcode = resload_SaveFile(size, name, address)
  1682.           D0       D1                         D0    A0      A1
  1683.          BOOL     ULONG                     ULONG  CPTR    APTR
  1684.  
  1685.    FUNCTION
  1686.         write specified memory area to file using specified name
  1687.  
  1688.    INPUTS
  1689.         size    - amount of bytes to write
  1690.         name    - name of file to write
  1691.         address - memory address of buffer to write
  1692.  
  1693.    EXAMPLE
  1694.                 ...
  1695.                 move.l  #512,d0                 ;size
  1696.                 lea     (_save,pc),a0           ;name
  1697.                 lea     $5ac20,a1               ;source
  1698.                 move.l  (_resload,pc),a2
  1699.                 jsr     (resload_SaveFile,a2)
  1700.                 ...
  1701.  
  1702.         _save   dc.b    "saved",0
  1703.  
  1704.    RESULT
  1705.         success   - TRUE on success
  1706.         errorcode - 0 on success
  1707.                     otherwise a dos-errorcode from dos.IoErr()
  1708.         if WHDLF_NoError is set, the function only returns on success
  1709.  
  1710.    BUGS
  1711.  
  1712.    NOTE
  1713.  
  1714.    SEE ALSO
  1715.         resload_SaveFileOffset
  1716.  
  1717. WHDLoad/resload_SaveFileOffset
  1718.  
  1719.    NAME
  1720.         resload_SaveFileOffset -- write memory to a file at offset
  1721.  
  1722.    SYNOPSIS
  1723.         success,error = resload_SaveFileOffset(size, offset, name, address)
  1724.           D0     D1                             D0     D1     A0      A1
  1725.          BOOL   ULONG                          ULONG  ULONG  CPTR    APTR
  1726.  
  1727.    FUNCTION
  1728.         write specified memory area to file at specified offset using
  1729.         specified name
  1730.  
  1731.    INPUTS
  1732.         size    - amount of bytes to write
  1733.         offset  - offset in the file to write
  1734.         name    - name of file to write
  1735.         address - memory address of buffer to write
  1736.  
  1737.    EXAMPLE
  1738.                 ...
  1739.                 move.l  #512,d0                 ;size
  1740.                 move.l  #$4000,d1               ;offset
  1741.                 lea     (_save,pc),a0           ;name
  1742.                 lea     $5ac20,a1               ;source
  1743.                 move.l  (_resload,pc),a2
  1744.                 jsr     (resload_SaveFileOffset,a2)
  1745.                 ...
  1746.  
  1747.         _save   dc.b    "saved",0
  1748.  
  1749.    RESULT
  1750.         success   - TRUE on success
  1751.         errorcode - 0 on success
  1752.                     otherwise a dos-errorcode from dos.IoErr()
  1753.         if WHDLF_NoError is set, the function only returns on success
  1754.  
  1755.    BUGS
  1756.  
  1757.    NOTE
  1758.         requires ws_Version >= 5
  1759.  
  1760.    SEE ALSO
  1761.         resload_SaveFile
  1762.  
  1763. WHDLoad/resload_SetCACR
  1764.  
  1765.    NAME
  1766.         resload_SetCACR -- set cachebility for BaseMem
  1767.  
  1768.    SYNOPSIS
  1769.         old = resload_SetCACR(new, mask)
  1770.          D0                    D0   D1
  1771.        ULONG                 ULONG ULONG
  1772.  
  1773.    FUNCTION
  1774.         modifies the cachebility for BaseMem, using this routine the
  1775.         instruction and the data cache can be enabled and disabled,
  1776.         the changes will affect the CACR (Cache Control Register) and
  1777.         the MMU-tables if it is used by WHDLoad
  1778.  
  1779.    INPUTS
  1780.         new  - new cache status
  1781.         mask - status bits to change
  1782.  
  1783.         valid values for new and mask are:
  1784.                 CACRF_EnableI - instruction cache
  1785.                 CACRF_EnableD - data cache
  1786.         (bits are defined in the standard include file "exec/execbase.i")
  1787.  
  1788.    EXAMPLE
  1789.         to enable instruction cache:
  1790.                 ...
  1791.                 move.l  #CACRF_EnableI,d0       ;new status
  1792.                 move.l  d0,d1                   ;status to change
  1793.                 move.l  (_resload,pc),a2
  1794.                 jsr     (resload_SetCACR,a2)
  1795.                 ...
  1796.  
  1797.    RESULT
  1798.         old - old cache status
  1799.  
  1800.    BUGS
  1801.  
  1802.    NOTE
  1803.         it is safe to call this routine from User or Supervisor mode and
  1804.         independend from the actual CPU type (also on 68000/010)
  1805.         if WHDLoad is launched with the option NoCache/S this routine will
  1806.         return without changing anything (BaseMem is always noncacheable)
  1807.         don't wonder if you see in the coredump or in a freezer that caches
  1808.         are enabled even if not enabled by the Slave: if the MMU is used by
  1809.         WHDLoad and no caches are switched on by the Slave, WHDLoad marks the
  1810.         BaseMem using the MMU as noncacheable-serialized, and enables both
  1811.         caches so that the memory of WHDLoad and the Slave are cachable to
  1812.         increase performance
  1813.         the routine performs automatically a resload_FlushCache before
  1814.         returning
  1815.  
  1816.    SEE ALSO
  1817.         resload_SetCPU, resload_FlushCache
  1818.  
  1819. WHDLoad/resload_SetCPU
  1820.  
  1821.    NAME
  1822.         resload_SetCPC -- control CPU setup
  1823.  
  1824.    SYNOPSIS
  1825.         old = resload_SetCPU(new, mask)
  1826.          D0                   D0   D1
  1827.        ULONG                ULONG ULONG
  1828.  
  1829.    FUNCTION
  1830.         change cachebility of memory areas and change the CPU setup
  1831.         see include file "whdload.i" for supported bit sets
  1832.  
  1833.    INPUTS
  1834.         new  - new setup
  1835.         mask - parts of the current setup to change
  1836.  
  1837.    EXAMPLE
  1838.         to enable the only instruction cache for BaseMem and ExpMem:
  1839.                 ...
  1840.                 move.l  #WCPUF_Base_WT|WCPUF_Exp_CB|WCPUF_IC,d0
  1841.                 move.l  #WCPUF_Base|WCPUF_Exp|WCPUF_IC|WCPUF_DC,d1
  1842.                 move.l  (_resload,pc),a2
  1843.                 jsr     (resload_SetCPU,a2)
  1844.                 ...
  1845.  
  1846.    RESULT
  1847.         old - the setup before
  1848.  
  1849.    BUGS
  1850.  
  1851.    NOTE
  1852.         it is safe to call this routine from User or Supervisor mode and
  1853.         independend from the actual CPU type (also on 68000/010)
  1854.         if WHDLoad is launched with the option NoCache/S this routine will
  1855.         return without changing anything
  1856.         the routine performs automatically a resload_FlushCache before
  1857.         returning
  1858.  
  1859.    SEE ALSO
  1860.  
  1861.  
  1862. WHDLoad.Slave/--Overview--
  1863.  
  1864. The WHDLoad.Slave contains the interface code which makes the installed
  1865. program able to load his files from harddisk. Additional it should realize
  1866. the possibility to quit the program to return to the OS.
  1867.  
  1868.    FORMAT
  1869.         is a standard amiga executable
  1870.    ATTENTION
  1871.         the Slave MUST consist of only ONE hunk (ONE section)
  1872.         the Slave MUST be 100% PC-relative
  1873.  
  1874.    STRUCTURE
  1875.         at the top of the Slave is "WHDLoadSlave" structure, after this
  1876.         follows the specific code and data
  1877.  
  1878.              STRUCTURE  WHDLoadSlave,0
  1879.                 STRUCT  ws_Security,4
  1880.                 STRUCT  ws_ID,8
  1881.                 UWORD   ws_Version
  1882.                 UWORD   ws_Flags
  1883.                 ULONG   ws_BaseMemSize
  1884.                 ULONG   ws_ExecInstall
  1885.                 RPTR    ws_GameLoader
  1886.                 RPTR    ws_CurrentDir
  1887.                 RPTR    ws_DontCache
  1888.              (  LABEL   ws_SIZEOF_pre_v4  )
  1889.                 UBYTE   ws_keydebug
  1890.                 UBYTE   ws_keyexit
  1891.              (  LABEL   ws_SIZEOF_pre_v8  )
  1892.                 ULONG   ws_ExpMem
  1893.              (  LABEL   ws_SIZEOF_pre_v10 )
  1894.                 RPTR    ws_name
  1895.                 RPTR    ws_copy
  1896.                 RPTR    ws_info
  1897.                 LABEL   ws_SIZEOF
  1898.  
  1899.         ws_Security
  1900.                 the code
  1901.                         moveq #-1,d0
  1902.                         rts
  1903.                 to avoid problems if somebody tries execute the Slave directly
  1904.  
  1905.         ws_ID
  1906.                 the string "WHDLOADS" to identify the program as a Slave
  1907.  
  1908.         (use the macro SLAVE_HEADER defined in the include file "whdload.i" to
  1909.         create the entries ws_Security and ws_ID)
  1910.  
  1911.         ws_Version
  1912.                 the version of WHDLoad that is required by the Slave,
  1913.                 some resload functions need at least a specific version of
  1914.                 WHDLoad, e.g. to use resload_CRC16 you must set ws_Version
  1915.                 to 3 or higher
  1916.                 on the other side the size of the WHDLoadSlave structure
  1917.                 differs for different Slave versions, e.g. if you set
  1918.                 ws_Version to 4 or higher you MUST initialize the fields
  1919.                 ws_keydebug and ws_keyexit and so on
  1920.  
  1921.         ws_Flags
  1922.                 WHDLF_Disk / WHDLB_Disk
  1923.                    this flag should enabled if the program uses
  1924.                    disk images (the result is a different working Preload/S)
  1925.                    (starting WHDLoad 0.143 this flag is obsolete)
  1926.                 WHDLF_NoError / WHDLB_NoError
  1927.                    if enabled every error occuring in a resload_#? function
  1928.                    lets WHDLoad immedately quit, and prompt an error requester
  1929.                    about the reason
  1930.                    using this flag it is not neccessary that the Slave checks
  1931.                    the return code resload_#? functions, it can be sure that
  1932.                    if a function returns it was successful (this will make the
  1933.                    Slave more simple)
  1934.                 WHDLF_EmulTrap / WHDLB_EmulTrap
  1935.                    this flag has only effect if the VBR is moved by WHDLoad
  1936.                    (i.e. the machine is at least a 68010 and the tooltype
  1937.                    NoVBRMove is not set)
  1938.                    if the flag is set all "trap #0..15"'s are emulated by the
  1939.                    exception handler in WHDLoad like the autovectors, i.e.
  1940.                    the handler checks if the vector ($80-$bc) is initialized
  1941.                    by the program, and if it is the routine will be called by
  1942.                    the handler
  1943.                 WHDLF_NoDivZero / WHDLB_NoDivZero
  1944.                    this flag has only effect if the VBR is moved by WHDLoad
  1945.                    (i.e. the machine is at least a 68010 and the tooltype
  1946.                    NoVBRMove is not set)
  1947.                    if the flag is set and a "Division by Zero" exception
  1948.                    occurs WHDLoad will not quit with an requester, but a
  1949.                    RTE will be performed
  1950.                    this maybe useful if you don't want use the option
  1951.                    NoVBRMove but the demo/game performs divisions by zero
  1952.                 WHDLF_Req68020 / WHDLB_Req68020
  1953.                    this flag indicates that the Slave/installed program
  1954.                    requires at least a MC68020 CPU, WHDLoad will check at
  1955.                    startup if this requirement matches, if it doesn't the
  1956.                    program will be terminated with an appropriate requester
  1957.                 WHDLF_ReqAGA / WHDLB_ReqAGA
  1958.                    this flag indicates that the Slave/installed program
  1959.                    requires at least the AGA chipset, WHDLoad will check at
  1960.                    startup if this requirement matches, if it doesn't the
  1961.                    program will be terminated with an appropriate requester
  1962.                 WHDLF_NoKbd / WHDLB_NoKbd
  1963.                    this flag says WHDLoad, that it doesn't should reply the
  1964.                    keyboard if a key was pressed, this must be used with
  1965.                    programs which doesn't check the keyboard from the PORTS
  1966.                    interrupt ($68), background: in normal operation when
  1967.                    NoVBRMove is inactive, WHDLoad checks if a key was pressed
  1968.                    on each interrupt, if a key has been pressed it checks the
  1969.                    rawkey code against QuitKey, DebugKey and FreezeKey, if it
  1970.                    doesn't match it looks if there is a initialized PORTS
  1971.                    interrupt ($68), if there is no, it replies the keyboard
  1972.                    that the keycode has been received, therefore the installed
  1973.                    program if it checks the keyboard from e.g. the VBI will
  1974.                    never receive any keycode, this flag avoids this behavior
  1975.                 WHDLF_EmulLineA / WHDLB_EmulLineA
  1976.                    this flag has only effect if the VBR is moved by WHDLoad
  1977.                    (i.e. the machine is at least a 68010 and the tooltype
  1978.                    NoVBRMove is not set)
  1979.                    if the flag is set all exceptions "Line-A" (caused by
  1980.                    opcodes starting with %1010) are emulated by the
  1981.                    exception handler in WHDLoad like the autovectors, i.e.
  1982.                    the handler checks if the vector ($28) is initialized
  1983.                    by the program, and if it is the routine which the vector
  1984.                    points to will be called by the handler
  1985.                 WHDLF_EmulTrapV / WHDLB_EmulTrapV
  1986.                    this flag has only effect if the VBR is moved by WHDLoad
  1987.                    (i.e. the machine is at least a 68010 and the tooltype
  1988.                    NoVBRMove is not set)
  1989.                    if the flag is set all exceptions caused by a TrapV
  1990.                    instruction are emulated by the exception handler in
  1991.                    WHDLoad like the autovectors, i.e. the handler checks if
  1992.                    the vector ($1C) is initialized by the program, and if it
  1993.                    is the routine which the vector points to will be called
  1994.                    by the handler
  1995.                 WHDLF_EmulChk / WHDLB_EmulChk
  1996.                    this flag has only effect if the VBR is moved by WHDLoad
  1997.                    (i.e. the machine is at least a 68010 and the tooltype
  1998.                    NoVBRMove is not set)
  1999.                    if the flag is set all exceptions caused by a Chk/Chk2
  2000.                    instruction are emulated by the exception handler in
  2001.                    WHDLoad like the autovectors, i.e. the handler checks if
  2002.                    the vector ($18) is initialized by the program, and if it
  2003.                    is the routine which the vector points to will be called
  2004.                    by the handler
  2005.                 WHDLF_EmulPriv / WHDLB_EmulPriv
  2006.                    this flag has only effect if the VBR is moved by WHDLoad
  2007.                    (i.e. the machine is at least a 68010 and the tooltype
  2008.                    NoVBRMove is not set)
  2009.                    if the flag is set all privilege violation exceptions are
  2010.                    emulated by the exception handler in WHDLoad like the
  2011.                    autovectors, i.e. the handler checks if the vector ($20) is
  2012.                    initialized by the program, and if it is the routine which
  2013.                    the vector points to will be called by the handler
  2014.                 WHDLF_EmulLineF / WHDLB_EmulLineF
  2015.                    this flag has only effect if the VBR is moved by WHDLoad
  2016.                    (i.e. the machine is at least a 68010 and the tooltype
  2017.                    NoVBRMove is not set)
  2018.                    if the flag is set all exceptions "Line-F" (caused by
  2019.                    opcodes starting with %1010) are emulated by the
  2020.                    exception handler in WHDLoad like the autovectors, i.e.
  2021.                    the handler checks if the vector ($2C) is initialized
  2022.                    by the program, and if it is the routine which the vector
  2023.                    points to will be called by the handler
  2024.                 WHDLF_ClearMem / WHDLB_ClearMem
  2025.                    if that falg is set WHDLoad will not init BaseMem with the
  2026.                    pattern $CCCCCCCC and ExpMem with $DDDDDDDD but simply
  2027.                    clear these memories
  2028.  
  2029.         ws_BaseMemSize
  2030.                 the size of the memory that is required by the program
  2031.                 the BaseMemory starts an $00000000 and ends at ws_BaseMemSize
  2032.                 (BaseMemory is always ChipMem)
  2033.                 this value must be multiple of $1000
  2034.                 the valid minimum is $2000, the maximum $200000
  2035.  
  2036.         ws_ExecInstall
  2037.                 obsolete, must be set to 0
  2038.  
  2039.         ws_GameLoader
  2040.                 a relative (to the start of the structure) 16-bit pointer
  2041.                 to the start code of the Slave
  2042.  
  2043.         ws_CurrentDir
  2044.                 a relative (to the start of the structure) 16-bit pointer
  2045.                 to a 0 terminated string which is the name of the path
  2046.                 where all files are stored (sub directory)
  2047.                 if no sub directory is used initialize this with 0
  2048.                 WHDLoad will change into this directory on startup
  2049.                 the path must be relative; you MUST NOT use any fucking lame
  2050.                 assignments
  2051.             BACKGROUND: if the assignment is not active on runtime the
  2052.                 dos.library will try to show a "Insert Disk ..." requester,
  2053.                 but intuition.library is locked, -> the system will hang
  2054.                 (deadlock) the user has only one alternative -> REBOOT
  2055.  
  2056.         ws_DontCache
  2057.                 a relative (to the start of the structure) 16-bit pointer
  2058.                 to a 0 terminated string which is a standard AmigaDOS
  2059.                 pattern (dos.ParsePattern, dos.MatchPattern)
  2060.                 all files matching this pattern are not cached by WHDLoad
  2061.                 this may be useful for savegames
  2062.                 if you dont want to use set the entry to 0
  2063.                 starting WHDLoad version 0.107 this is obsolete, because saved
  2064.                 files will be written also to the file cache
  2065.  
  2066.       the following variables are only evaluated by WHDLoad if ws_Version
  2067.       is set to >= 4
  2068.       the following variables MUST be initialized if you set ws_Version
  2069.       to >= 4
  2070.  
  2071.         ws_keydebug
  2072.                 the raw key code to exit with debug
  2073.                 this variable will be overwritten by WHDLoad if the option
  2074.                 DebugKey= is set in the global config or as CLI argument or
  2075.                 ToolType with the specified value from there
  2076.                 if the Slave provides an own handler to support a debug option
  2077.                 via the keyboard it should use this entry for comparision, so
  2078.                 it will be possible for the user to change the default key
  2079.                 suggestion from the Slave
  2080.                 this entry is also used by WHDLoad's internal handler if the
  2081.                 VBR is moved (requires 68010+ and that NoVBRMove is not set)
  2082.                 (recommend is $58 = "F9")
  2083.  
  2084.         ws_keyexit
  2085.                 the raw key code to exit
  2086.                 similar to ws_keydebug
  2087.                 (recommend is $59 = "F10")
  2088.  
  2089.       the following variables are only evaluated by WHDLoad if ws_Version
  2090.       is set to >= 8
  2091.       the following variables MUST be initialized if you set ws_Version
  2092.       to >= 8
  2093.  
  2094.         ws_ExpMem
  2095.                 if the installed program requires expansion memory, the size
  2096.                 must be specified here, WHDLoad will allocate a memory block
  2097.                 of this size and writes a pointer to the start of the
  2098.                 allocated memory back to this entry, the memory is granted to
  2099.                 be aligned to $1000 (4096 bytes), the size specified must be
  2100.                 an multiple of $1000 (4096), if WHDLoad fails to allocate
  2101.                 this memory it terminates with an appropriate error requester,
  2102.                 that means the Slave will always get a valid pointer here
  2103.                 - starting WHDLoad version 10.2 the value can be negative,
  2104.                 which means that the memory is optional and not absolute
  2105.                 required, WHDLoad will try to allocate it and if it fails it
  2106.                 will set ws_ExpMem to zero, the Slave has to check ws_ExpMem
  2107.                 therefore
  2108.  
  2109.       the following variables are only evaluated by WHDLoad if ws_Version
  2110.       is set to >= 10
  2111.       the following variables MUST be initialized if you set ws_Version
  2112.       to >= 10
  2113.  
  2114.         ws_name
  2115.                 a relative (to the start of the structure) 16-bit pointer
  2116.                 to a 0 terminated string containing the name of the installed
  2117.                 program, e.g. "Super Hang Off"
  2118.         ws_copy
  2119.                 a relative (to the start of the structure) 16-bit pointer
  2120.                 to a 0 terminated string containing the copyright of the
  2121.                 installed program, the string should start with the year
  2122.                 followed by the company holding the copyright, multiple years
  2123.                 or companies should be separated with ", "
  2124.                 e.g. "1983 Schega, 1989 Bad Dreams"
  2125.         ws_info
  2126.                 a relative (to the start of the structure) 16-bit pointer
  2127.                 to a 0 terminated string containing addional infos about the
  2128.                 installed program, the string may also contain line feeds
  2129.                 ($0a), the character -1 has a special meaning - it results in
  2130.                 a line feed and an additional vertical skip of the half font
  2131.                 height, e.g.:
  2132.                         dc.b    "installed & fixed by Wepl",10
  2133.                         dc.b    "version 1.4 (06.06.2066)",-1
  2134.                         dc.b    "greetings to the world",0
  2135.  
  2136.  
  2137.    CONVENTIONS for ws_GameLoader
  2138.         the status of the system at the moment of calling ws_GameLoader:
  2139.  
  2140.         CPU:
  2141.                 SR   = $2000           Supervisor-mode, all interrupts enabled
  2142.                 SSP  = ws_BaseMemSize  at end of BaseMem
  2143.                 USP  = SSP-$400        at end of BaseMem - 1024
  2144.                 A0   = ResidentLoader  pointer to the resident Jump-Tower
  2145.                 D0-D7/A1-A6 random     (D0=$d0d0d0d0 D1=...)
  2146.  
  2147.                 nothing more is interesting from the Slave programmes point of
  2148.                 view, all special registers like VBR,SFC,DFC,CAAR,CACR,MSP,TC,
  2149.                 MMUSR,CRP,SRP,URP,TT0,TT1,DTT0,DTT1,ITT0,ITT1,PCR,BUSCR are
  2150.                 WHDLoad private and MUST NOT BE CHANGED.
  2151.  
  2152.         BaseMem:
  2153.                 $00000000 = 0
  2154.                 $00000004 = $f0000001  any try to use the execbase should
  2155.                                        create a "Address Error" exception
  2156.                 $00000008 - $00000400
  2157.                           = $CCCCCCCC  if WHDLoad has moved the VBR else
  2158.                           = Handler    the address of a exception handler
  2159.                                        inside WHDLoad
  2160.                 $00000400 - ws_BaseMemSize
  2161.                           = $CCCCCCCC  this memory fill pattern is used to
  2162.                                        easy recognize modified memory
  2163.                 $00001000 = $FFFFFFFE  the copper instruction "CWAIT $ff,$1fe"
  2164.  
  2165.         ExpMem:
  2166.                 the memory is filled with the pattern "$DDDDDDDD"
  2167.  
  2168.         custom:
  2169.                 dmacon = 0             all dma's off
  2170.                 intena = 0             all interrupts off
  2171.                 cop1lc = cop2lc = $1000
  2172.                 a AGA-machine is switched to OCS
  2173.  
  2174.         cia's:
  2175.                 ------- ciaa ------     ------- ciab ------
  2176.                 pra in  = %00000000     pra in  = %00000000
  2177.                 pra out = %11111100     pra out = %11111000
  2178.                 ddra    = %00000011     ddra    = %11000000
  2179.                 prb in  = %00000000     prb in  = %00000000
  2180.                 prb out = %00000000     prb out = %11111111
  2181.                 ddrb    = %00000000     ddrb    = %11111111
  2182.                 ta      =     $21ff     ta      =     $ffff
  2183.                 tb      =     $21ff     tb      =     $ffff
  2184.                 event   =   $000000     event   =   $000000
  2185.                (alarm   =   $ffffff     alarm   = execbase.EClockFrequency
  2186.                         the alarm values are no longer initialized starting
  2187.                         WHDLoad version 13.1 to avoid compatibility problems
  2188.                         on Kickstart 2.0)
  2189.                 sdr     =       $00     sdr     =       $00
  2190.                 icr     = %00000000     icr     = %00000000
  2191.                 icm     = %00001000     icm     = %00000000
  2192.                 cra     = %00000000     cra     = %00000000
  2193.                 crb     = %00000000     crb     = %00000000
  2194.  
  2195.    SEE ALSO
  2196.         example Slaves
  2197.  
  2198.